package com.hzdl.car.contorlle;

import com.github.pagehelper.PageInfo;
import com.hzdl.car.bean.Log;
import com.hzdl.car.service.LogService;
import com.hzdl.car.util.HzdlResultJson;
import com.hzdl.car.vo.LogVo;
import com.hzdl.car.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("log")
public class LogControlle {
    @Autowired
    private LogService logService;

    @RequestMapping("init")
    public HzdlResultJson logInit(LogVo logVo){
        PageInfo<Log> pageInfo = logService.findWhere(logVo);
        return new HzdlResultJson(pageInfo.getTotal(),pageInfo.getList());

    }

    @RequestMapping("delete")
    public HzdlResultJson delete(Integer id){
        int row = logService.delete(id);
        if (row>0){
            return HzdlResultJson.DELETE_SUCCESS();
        }else {
            return HzdlResultJson.DELETE_FAIL();
        }
    }

    @RequestMapping("deleteAll")
    public HzdlResultJson deleteAll (LogVo logVo, @RequestParam(value = "ids[]") Integer[] ids){
        int row =0;
        for(Integer id:ids){
            row+=logService.delete(id);
        }

        if (row>0){
            return HzdlResultJson.DELETE_ALL_SUCCESS();
        }else{
            return HzdlResultJson.DELETE_ALL_FAIL();
        }
    }

}
